package com.security.it.web.aspect;

import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.security.it.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import net.minidev.json.JSONArray;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Slf4j
@Aspect
@Component
public class TimeAspect {

    @Around("execution(* com.security.it.web.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint point) throws Throwable {
        log.info("time aspect start");
        Stopwatch stopwatch = Stopwatch.createStarted();
        log.info("args is :{}", JsonUtil.toJSONString(point.getArgs()));
        Object object = point.proceed();
        log.info("方法耗时：{}ms", stopwatch.elapsed(TimeUnit.MILLISECONDS));
        log.info("time aspect end");
        return object;
    }

}
